package com.ssi.util;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbcp.BasicDataSource;

public class DBUtil {
	public static List<Connection> listPool=new ArrayList<Connection>();
	private static String url="jdbc:mysql://127.0.0.1:3306/ssi_1?useUnicode=true&characterEncoding=utf-8";
	private static String username="root";
	private static String password="";
	static{		
		try {
			Class.forName("com.mysql.jdbc.Driver");
			BasicDataSource basicDataSource = new BasicDataSource();
			basicDataSource.setUrl(url);			
			basicDataSource.setUsername(username);
			basicDataSource.setPassword(password);
			basicDataSource.setMaxActive(6);
			int c=1;
			for (int i = 0; i < 10; i++) {
				Connection connection = basicDataSource.getConnection();
				listPool.add(connection);	
				System.out.println("");
				System.out.println("线程"+c+"开始启动");
				new MyThread(connection, c).start();
				c++;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		
	}
}
class MyThread extends Thread{
	private Connection connection;
	private int count;
	public MyThread(Connection connection,int count) {
		this.count=count;
		this.connection=connection;
	}
	@Override
	public void run() {
		try {
			connection.close();
			System.out.println("线程"+count+"开始启动");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
}